package io.renren.modules.wyzs.service.impl;

import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.wyzs.dao.FacortyDao;
import io.renren.modules.wyzs.entity.FactoryInfo;
import io.renren.modules.wyzs.service.FactoryService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class FactoryServiceImpl implements FactoryService {

    @Autowired
    FacortyDao facortyDao;


    @Override
    public List<FactoryInfo> queryList(Map<String, Object> map) {
        return facortyDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return facortyDao.queryTotal(map);
    }

    @Override
    public FactoryInfo queryInfo(String id) {
        return facortyDao.getEntityById(id);
    }

    @Override
    public void update(FactoryInfo factoryInfo) {
        facortyDao.update(factoryInfo);
    }

    @Override
    public void save(FactoryInfo factoryInfo) {
        facortyDao.save(factoryInfo);
    }

    @Override
    public void delete(String id) {
        facortyDao.delete(id);
    }

    @Override
    public List<FactoryInfo> getFactoryList(Map<String, Object> map) {
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        map.put("username",username);
        return facortyDao.getFactoryList(map);
    }

    @Override
    public List<FactoryInfo> getFactoryListX(Map<String, Object> map){
        String username = ((SysUserEntity) SecurityUtils.getSubject().getPrincipal()).getUsername();
        map.put("username",username);
        return facortyDao.getFactoryListX(map);
    }

    @Override
    public FactoryInfo getFactoryById(String factoryId) {
        return facortyDao.getFactoryById(factoryId);
    }

    public String getUrlById(String id)
    {
        FactoryInfo factoryInfo=this.getFactoryById(id);
        if(factoryInfo!=null)
        {
                return factoryInfo.getFactoryURL();
        }else {
            return "工厂Id不存在";
        }
    }

}
